local assets =
{
    Asset("ANIM", "anim/yuemiheng_equipment.zip"),
	Asset("ATLAS", "images/inventoryimages/yuemiheng_cape.xml"), 
    Asset("IMAGE", "images/inventoryimages/yuemiheng_cape.tex"),
}

local function OnBlocked(owner, data) 
    owner.SoundEmitter:PlaySound("dontstarve/wilson/hit_armour")
end

local function onequip(inst, owner)
    owner.AnimState:OverrideSymbol("backpack", "yuemiheng_equipment", "00000")
    owner.AnimState:OverrideSymbol("swap_body", "yuemiheng_equipment", "00000")

    if owner.components.hunger then
        owner.components.hunger.burnratemodifiers:SetModifier(inst,TUNING.MOD_YUEMIHENG.CAPE.HUNGER_RATE,'yuemiheng_cape_buff')
    end
end

local function onunequip(inst, owner)
    owner.AnimState:ClearOverrideSymbol("swap_body")
    owner.AnimState:ClearOverrideSymbol("backpack")

    if owner.components.hunger then
        owner.components.hunger.burnratemodifiers:RemoveModifier(inst, 'yuemiheng_cape_buff')
    end
end

local function onopen(inst)
    
end 

local function onclose(inst)
    
end

local function fn()
    local inst = CreateEntity()

    inst.entity:AddTransform()
    inst.entity:AddAnimState()
    inst.entity:AddNetwork()

    MakeInventoryPhysics(inst)

    inst.AnimState:SetBank("yuemiheng_cape") 
    inst.AnimState:SetBuild("yuemiheng_equipment")
    inst.AnimState:PlayAnimation("idle",true)

    inst:AddTag("wood")

    inst.foleysound = "dontstarve/movement/foley/logarmour"

    inst.entity:SetPristine()

    if not TheWorld.ismastersim then
        inst.OnEntityReplicated = function(inst)
            inst.replica.container:WidgetSetup("yuemiheng_cape")
        end
        return inst
    end

    inst:AddComponent("inspectable") 

    inst:AddComponent("inventoryitem")
    inst.components.inventoryitem.imagename = "yuemiheng_cape"
	inst.components.inventoryitem.atlasname = "images/inventoryimages/yuemiheng_cape.xml" 

    inst:AddComponent("equippable")
    inst.components.equippable:SetOnEquip(onequip)
    inst.components.equippable:SetOnUnequip(onunequip)
    inst.components.equippable.walkspeedmult = TUNING.MOD_YUEMIHENG.CAPE.WALKSPEEDMULT

    inst:AddComponent('armor')
    inst.components.armor:InitCondition(TUNING.MOD_YUEMIHENG.CAPE.DURABILITY, TUNING.MOD_YUEMIHENG.CAPE.ABSORB)

    inst:AddComponent("insulator")
    inst.components.insulator:SetInsulation(TUNING.MOD_YUEMIHENG.CAPE.AVOID_COLD)

    inst:AddComponent("container")
    inst.components.container:WidgetSetup("yuemiheng_cape")
    inst.components.container.onopenfn = onopen
    inst.components.container.onclosefn = onclose

    inst:AddComponent('preserver')
    inst.components.preserver:SetPerishRateMultiplier(TUNING.MOD_YUEMIHENG.CAPE.PERISH)

    MakeHauntableLaunch(inst)

    return inst
end

return Prefab("yuemiheng_cape", fn, assets) 
